1419B - Stairs - CodeForces Solution


brute force constructive algorithms greedy implementation math *1200

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>

#define     pb                push_back
#define     all(v)            v.begin(),v.end()
#define     vl                vector<int>
#define     in(a)             for(auto &x : a) cin>>x;
#define     out(a)            for(auto &x : a) cout<<x<<" "
#define     pr(a)             cout<<a<<endl
#define     N                 (int)(1e5 + 10) ///100010
#define     nl                "\n"
#define     mod               1000000007
#define     pr(x)             cout<<x<<"\n"
#define     sz(x)             ((int) x.size())
#define     test              int T; cin>>T; while(T--)
#define     yes               cout<<"Yes"<<endl;
#define     no               cout<<"No"<<endl;
#define     lcm(a,b)           (a*(b/__gcd(a,b)))


typedef long long ll;
typedef long double ld;
typedef long long int lli;
using namespace std;

vector<int> graph[N];
bool visited[N];
ll x;

//binary search using recursion
void bs(int l, int h, int arr[], int n)
{
    if(l<=h)
    {
        int m = (l+h)/2;
        if(n<m) bs(m+1, h, arr, n);
        else if(n>m) bs(l, m-1, arr, n);
        else x = m; ///return Answer
    }

}

//Basic DFS
void dfs(int vertex)
{
//    if(visited[vertex]) return;
    visited[vertex] = true;

    for(auto child : graph[vertex])
    {
        if(visited[child]) continue;
        dfs(child);
    }
}


void solve()
{
    ll n;
    cin>>n;

    ll i = 1, ans, sum = 0;
    while(1)
    {
        ll x = pow(2,i) - 1;
        sum+=(x*(x+1))/2;
        if(sum>n) break;
        ans = i;
        i++;
    }
    cout<<ans<<endl;
}

int main()
{
//    ios_base::sync_with_stdio(0);cin.tie(0);
    ll t;
    cin>>t;
    while(t--) solve();


}











Comments

Submit
0 Comments
More Questions

1091A - New Year and the Christmas Ornament
1352B - Same Parity Summands
1102A - Integer Sequence Dividing
630B - Moore's Law
1004A - Sonya and Hotels
1680B - Robots
1690A - Print a Pedestal (Codeforces logo)
1295A - Display The Number
1077A - Frog Jumping
1714G - Path Prefixes
1369C - RationalLee
289B - Polo the Penguin and Matrix
1716A - 2-3 Moves
1670B - Dorms War
1716B - Permutation Chain
987A - Infinity Gauntlet
1676G - White-Black Balanced Subtrees
1716D - Chip Move
1352F - Binary String Reconstruction
1487B - Cat Cycle
1679C - Rooks Defenders
56A - Bar
1694B - Paranoid String
35A - Shell Game
1684A - Digit Minimization
43B - Letter
1017A - The Rank
1698B - Rising Sand
235A - LCM Challenge
1075B - Taxi drivers and Lyft